package com.minelx.table.core.series.source;

import java.util.function.Function;
import java.util.stream.Stream;

public class MappedSource<T, R> implements Source<R> {
	private final Source<T> decorated;

	private final Function<? super T, R> mapper;

	public MappedSource(Source<T> decorated, Function<? super T, R> mapper) {
		this.decorated = decorated;
		this.mapper = mapper;
	}

	@Override
	public R at(long at) {
		return mapper.apply(decorated.at(at));
	}

	@Override
	public long len() {
		return decorated.len();
	}

	@Override
	public Stream<R> stream() {
		return decorated.stream().map(mapper);
	}
}
